{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "#本章需导入的模块\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline\n",
    "plt.rcParams['font.sans-serif']=['SimHei']  #解决中文显示乱码问题\n",
    "plt.rcParams['axes.unicode_minus']=False\n",
    "import warnings\n",
    "warnings.filterwarnings(action = 'ignore')\n",
    "from sklearn.metrics import confusion_matrix,f1_score,roc_curve, auc, precision_recall_curve,accuracy_score\n",
    "from sklearn.model_selection import train_test_split,KFold,LeaveOneOut,LeavePOut # 数据集划分方法\n",
    "from sklearn.model_selection import cross_val_score,cross_validate # 计算交叉验证下的测试误差\n",
    "from sklearn import preprocessing\n",
    "import sklearn.linear_model as LM\n",
    "from sklearn import neighbors"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "一元回归模型的截距项:0.955268\n",
      "一元回归模型的回归系数: [60.58696023]\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYYAAAESCAYAAAD5d3KwAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nO3de5xUdf348dd7Lyw3FUEQMeRiqKGIIiKrkqPiBetbhhV2Ef2mYmWW377fMDXLayr9MpXUotCkzEtK5TVQYxV1UQFBFBNRuYk3LoqK7GXm/fvjc2aZM8ycmbPs2ZmzvJ+Pxz6Yz5kzZz+zM3zen/sRVcUYY4xJqyh1BowxxpQXCwzGGGN8LDAYY4zxscBgjDHGxwKDMcYYHwsMxsSYiEip89DR2N/UAkOHJCIni8ikiK5dJSKve4/XikgX7/FpInJzEa+fJyLH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Ik1W/lsjDHGx1oMxhhjfCwwGGOM8bHAYIwxxscCgzHGGB8LDMYYY3wsMBhjjPGxwGCMMcbn/wPvcQD+oe3hRwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "data=pd.read_excel('北京市空气质量数据.xlsx')\n",
    "data=data.replace(0,np.NaN)\n",
    "data=data.dropna()\n",
    "data=data.loc[(data['PM2.5']<=200) & (data['SO2']<=20)]\n",
    "\n",
    "###一元回归\n",
    "X=data[['CO']]\n",
    "y=data['PM2.5']\n",
    "modelLR=LM.LinearRegression()\n",
    "modelLR.fit(X,y)\n",
    "print(\"一元回归模型的截距项:%f\"%modelLR.intercept_)\n",
    "print(\"一元回归模型的回归系数:\",modelLR.coef_)\n",
    "plt.scatter(data['CO'],data['PM2.5'],c='green',marker='.')\n",
    "plt.title('PM2.5与CO散点图和回归直线(MSE=%f)'%(sum((y-modelLR.predict(X))**2)/len(y)))\n",
    "plt.xlabel('CO')\n",
    "plt.ylabel('PM2.5')\n",
    "plt.xlim(xmax=4, xmin=1)\n",
    "plt.ylim(ymax=300,ymin=1)\n",
    "plt.plot(data['CO'],modelLR.predict(X),linewidth=0.8)\n",
    "plt.show()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "多元回归模型的截距项:-1.249076\n",
      "多元回归模型的回归系数: [ 0.85972339 56.85521851]\n",
      "多元回归模型的MSE:672.048805\n"
     ]
    }
   ],
   "source": [
    "##多元回归\n",
    "X=data[['SO2','CO']]\n",
    "y=data['PM2.5']\n",
    "modelLR=LM.LinearRegression()\n",
    "modelLR.fit(X,y)\n",
    "print(\"多元回归模型的截距项:%f\"%modelLR.intercept_)\n",
    "print(\"多元回归模型的回归系数:\",modelLR.coef_)\n",
    "print(\"多元回归模型的MSE:%f\"%(sum((y-modelLR.predict(X))**2)/len(y)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "说明：\n",
    "1、这里以空气质量监测的部分数据为例，对PM2.5（输出变量）进行预测。首先考虑只有一个输入变量CO的情况，建立一元线性回归模型。然后，研究SO2和CO对PM2.5的影响，建立多元线性回归模型。\n",
    "2、建立线性回归模型需引用sklearn中的linear_model。首先，modelLR=LM.LinearRegression()定义modelLR对象为线性模型；然后，modelLR.fit(X,y)表示基于给出的X和y估计模型参数。其中，X为输入变量（矩阵形式），y为输出变量。最后，modelLR.predict(X)表示将X带入回归方程计算y的预测值。\n",
    "3、线性回归模型参数的估计值存储在intercept_和.coef_属性中，依次为截距项和回归系数。\n",
    "4、在研究CO对PM2.5的影响时，CO的回归系数估计值（60.59）大于0，表示其他因素不变条件下，CO浓度增加一个单位将导致PM2.5均值增加60.59。\n",
    "5、在研究SO2和CO对PM2.5的影响时，CO的回归系数估计值（56.86）大于SO2（0.86），表明CO对PM2.5的正向贡献大于SO2。"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
